#include <webby/server.hxx>
#include <boost/shared_ptr.hpp>

#include <iostream>

using namespace webby;

int kbhit(void)
{
struct timeval tv;
fd_set read_fd;

tv.tv_sec=0;
tv.tv_usec=0;
FD_ZERO(&read_fd);
FD_SET(0,&read_fd);

if(select(1, &read_fd, NULL, NULL, &tv) == -1)
return 0;

if(FD_ISSET(0,&read_fd))
return 1;

return 0;
}

int main( int argc, char *argv[] ) 
{
	boost::shared_ptr<webby::Server> webby = boost::shared_ptr<webby::Server>( new webby::Server );
	webby->start( 82, 8 );	
	while ( webby->isRunning() ) {
		webby->handleEvents();
//		std::cout << "In loop" << std::endl;
		if (kbhit()) 
		{
			webby->quit();
		}
	}
	std::cout << "Exiting...";
	return 0;
}
